package com.property.manage.controller.flowingWater;

import com.guardchina.framework.mybatis.model.CustomPage;
import com.property.manage.model.flowingWater.ArrearsDetailEntity;
import com.property.manage.model.flowingWater.ArrearsVo;
import com.property.manage.model.print.ArrearsPayBillVo;
import com.property.manage.service.flowingWater.ArrearsDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author lwb
 */
@Api(tags = "欠费管理")
@RestController
@RequestMapping("/arrears")
@AllArgsConstructor
@Validated
public class ArrearsController {

    private ArrearsDetailService arrearsDetailService;

    @ApiOperation("欠费记录")
    @GetMapping("/page")
    public CustomPage<ArrearsVo> page(@ApiParam("当前页码") @RequestParam("pageNo") @NotNull(message = "当前页码为空") Long pageNo,
                                      @ApiParam("每页条数") @RequestParam("pageSize") @NotNull(message = "每页条数为空")Long pageSize,
                                      @ApiParam("小区编号") @RequestParam(value = "villageId", required = false) Integer villageId,
                                      @ApiParam("楼栋号") @RequestParam(value = "building", required = false) Integer building,
                                      @ApiParam("单元号") @RequestParam(value = "unit", required = false) Integer unit,
                                      @ApiParam("房间号") @RequestParam(value = "roomNumber", required = false) String roomNumber){
        return arrearsDetailService.page(pageNo, pageSize, villageId, building, unit, roomNumber);
    }

    @ApiOperation("欠费明细记录")
    @GetMapping("/detail/list")
    public List<ArrearsDetailEntity> detailList(@ApiParam("楼栋编号") @RequestParam("buildingId") @NotNull(message = "楼栋编号为空") Integer buildingId){
        return arrearsDetailService.detailList(buildingId);
    }

    @ApiOperation("欠费收取")
    @PostMapping("/charge")
    public ArrearsPayBillVo charge(@ApiIgnore("用户编号") @RequestParam("userId")  @NotNull(message = "您尚未登录") Integer userId,
                                   @ApiParam("楼栋编号") @RequestParam("buildingId") @NotNull(message = "楼栋编号为空") Integer buildingId,
                                   @ApiParam("欠费编号（转换成json数据）") @RequestParam("arrearsIds") @NotBlank(message = "欠费编号为空") String arrearsIds,
                                   @ApiParam("合计金额") @RequestParam("totalMoney") @NotNull(message = "合计金额为空") BigDecimal totalMoney,
                                   @ApiParam("减免金额") @RequestParam("deductionAmount") @NotNull(message = "减免金额为空") BigDecimal deductionAmount,
                                   @ApiParam("收款金额") @RequestParam("chargeMoney") @NotNull(message = "收款金额") BigDecimal chargeMoney,
                                   @ApiParam("支付方式") @RequestParam("payType") @NotBlank(message = "支付方式") String payType,
                                   @ApiParam("使用预存") @RequestParam(value = "useStorage", required = false, defaultValue = "false") Boolean useStorage,
                                   @ApiParam("零钱转存") @RequestParam(value = "storageReturn", required = false, defaultValue = "false")  Boolean storageReturn,
                                   @ApiParam("是否打印") @RequestParam(value = "print", required = false, defaultValue = "false")  Boolean print,
                                   @ApiParam("备注") @RequestParam(value = "remark", required = false)  String remark){

        return arrearsDetailService.charge(userId, buildingId, arrearsIds, totalMoney, deductionAmount, chargeMoney, payType, useStorage, storageReturn, print, remark);
    }



    @ApiOperation("欠费导出")
    @PostMapping("/export")
    public void export(@ApiParam("小区编号") @RequestParam(value = "villageId", required = false) Integer villageId,
                       @ApiParam("楼栋号") @RequestParam(value = "building", required = false) Integer building,
                       @ApiParam("单元号") @RequestParam(value = "unit", required = false) Integer unit,
                       @ApiParam("房间号") @RequestParam(value = "roomNumber", required = false) String roomNumber,
                       HttpServletRequest request,
                       HttpServletResponse response){
        arrearsDetailService.export(villageId, building, unit, roomNumber, request, response);
    }

}
